package client;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class ThreadEnvoiUDP extends Thread {

	private InetAddress ip;
	private int port;
	private String msg;
	
	public ThreadEnvoiUDP(InetAddress ip, int port, String msg) {
		super();
		this.ip = ip;
		this.port = port;
		this.msg = msg;
	}
	
	public void run()
	{
		try
		{
			DatagramSocket s = new DatagramSocket();
			byte[] buf = msg.getBytes();
			DatagramPacket packet = new DatagramPacket(buf, buf.length, ip, port);
			System.out.println("Envoi UDP: "+msg);
			s.send(packet);
		}
		catch (IOException ex)
		{
			System.out.println("probleme envoi udp");
			ex.printStackTrace();
		}
	}

}
